import { Object3D } from "../objects/Object3D";
import { post } from "../utils/Client";
import { MapKey, Mapper } from "../utils/Map";
import { defineReactive } from "../utils/Observe";

/**灯光 */
class Light extends Object3D {
  /**光照强度 */
  intensity: number = undefined;

  /**光照颜色 */
  color: string = undefined;

  /**开启阴影 */
  @Mapper("bshadow")
  shadow: boolean = undefined;

  constructor(options) {
    super();
    Light.prototype.isLight = true;

    Mapper.map(this, options);
    defineReactive(this, "intensity", (value, key) => {
      this.putProperty(key, key);
    });
    defineReactive(this, "color", (value, key) => {
      this.putProperty(key, key);
    });
    defineReactive(this, "shadow", (value, key) => {
      const { property } = Reflect.getMetadata(MapKey, this, key);
      this.putProperty(key, property, false, property);
    });
  }

  

  private putProperty(prop, key, expand?, alias?) {
    if (expand) {
      post("preview_light", {
        ...this[prop],
        guid: this.guid,
        key,
      });
    } else {
      post("preview_light", {
        [alias || prop]: this[prop],
        guid: this.guid,
        key,
      });
    }
  }
}

export { Light };
